package edu.ilstu.mind.ise.ccp.mindmodule;

import edu.ilstu.mind.ise.ccp.logger.Logger;
import edu.ilstu.mind.ise.ccp.message.MasterMessageFactory;
import edu.ilstu.mind.ise.ccp.message.Message;
import edu.ilstu.mind.ise.ccp.message.MessageSender;

/**
 * Interface for the Mind Module. All messages that go through the CCP are first
 * routed through the mind module. The mind module has the ability to block
 * messages by returning false when onMessage is called. It also has a special
 * message sender that allows it to send messages as if it was any module.
 * 
 * @author Eric Thill
 * 
 */

public interface MindModule {

	/**
	 * Sets the {@link MasterMessageFactory} that is used to create messages.
	 * This method can only be called once and must be called before init().
	 * 
	 * @param sender
	 *            The MasterMessageSender
	 */
	void setMessageFactory(MasterMessageFactory messageFactory);
	
	/**
	 * Sets the {@link MessageSender} that is used to send messages via the CCP.
	 * This method can only be called once and must be called before init().
	 * 
	 * @param sender
	 *            The MasterMessageSender
	 */
	void setMessageSender(MessageSender sender);

	/**
	 * Sets the {@link Logger}. This method can only be called once and must be
	 * called before init().
	 * 
	 * @param logger
	 *            The Logger
	 */
	void setLogger(Logger logger);

	/**
	 * Initialize method <br>
	 * Called after the {@link MessageSender} and {@link Logger} has been set
	 */
	void init();

	/**
	 * Called for every message that is sent over the CCP. The MindModule is
	 * allowed to block messages by returning false.
	 * 
	 * @param message
	 *            The received message
	 * @return if the message should be allowed to be processed
	 */
	boolean onMessage(Message message);
}
